namespace SFPortal.SF.UserControls
{
	using System;
	using System.Data;
	using System.Drawing;
	using System.Web;
	using System.Web.UI;
	using System.Web.UI.WebControls;
	using System.Web.UI.HtmlControls;

	using WorkflowServices = ScenarioFramework.WorkflowEngine.DataModel.WorkflowServices;

	using System.Collections;

	public partial class Services : System.Web.UI.UserControl
	{
	
		public class ServiceTab
		{
			public string Name = String.Empty;
			public string Url = String.Empty;

			public ServiceTab(string name, string url) 
			{
				Name = name;
				Url = url;
			}
		}

		protected void Page_Load(object sender, System.EventArgs e)
		{
            
			ArrayList colService = new ArrayList();

			if ( !Page.IsPostBack ) 
			{
                ScenarioFramework.WAPI.Response wapiResponse = new ScenarioFramework.WAPI.Response();
                string sDB = ScenarioFramework.WAPI.Session.GetScenarioDBDirectory(ref wapiResponse);
                string sServiceXML = String.Format ("{0}\\common\\services.xml", sDB);   
                
				WorkflowServices.XMLServices services = new WorkflowServices.XMLServices();
                services.Load(sServiceXML);
                //string Answare = ScenarioFramework.WAPI.Service.GetServiceForUser(Page.User.Identity.Name, "Context", "General", ref response);
			
				for ( int i=0; i<services.Count;i++)
				{
					WorkflowServices.XMLService service = (WorkflowServices.XMLService)services[i];

					string sUrl="~/SF/Forms/WaitingPage";
					sUrl= sUrl + ".aspx?Action=CreateMainProcess&ProcessName=" + service.Workflow;
					colService.Add( new ServiceTab( service.Name, sUrl));
				}

				lstServices.DataSource = colService;
				lstServices.DataBind();

			}
		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		///		Required method for Designer support - do not modify
		///		the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.lstServices.ItemDataBound += new System.Web.UI.WebControls.DataListItemEventHandler(this.lstServices_ItemDataBound);

		}
		#endregion

		private void lstServices_ItemDataBound(object sender, System.Web.UI.WebControls.DataListItemEventArgs e)
		{
			ServiceTab objTab = (ServiceTab)e.Item.DataItem;
			HyperLink lnkTab = (HyperLink)e.Item.FindControl("lnkTab");

			lnkTab.Text = objTab.Name;
			lnkTab.NavigateUrl = objTab.Url;
			
			/*if (String.Compare(CurrentTabName, objTab.Name)==0)
				e.Item.CssClass = "tabactive";
			else
				e.Item.CssClass = "tab";
			*/
			lnkTab.CssClass ="active";
		}
	}
}
